import os, sys, re

def anyfile(names):
    for n in names:
        try:
            return file(n)
        except: pass
    raise IOError, 'found none of files %s' % names

SYSCALL_NAMES = {}
#define __NR_rt_tgsigqueueinfo                  297
RE_SYSCALL = re.compile('^#define\s+__NR_(\S+)\s+(\d+)')
for line in anyfile(['/usr/include/asm/unistd_64.h',
                     '/usr/include/asm-x86_64/unistd.h']):
    r = RE_SYSCALL.search(line)
    if r:
        name, num = r.group(1), int(r.group(2))
        globals()['NR_%s' % name] = num
        SYSCALL_NAMES[num] = name
#        print name, num